package com.example.enums;

import java.util.LinkedHashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 球类枚举
 * @ClassName: BallEnum
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author liuwj3
 * @date 2019年2月15日 上午11:17:43
 *
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum BallEnum implements BaseEnum<BallEnum, String> {
	BASKET_BALL("1", "篮球"), FOOT_BALL("2", "足球"), VOLLEY_BALL("3", "排球");
	private String ballCode;
	// @JsonValue // 只序列化该注解标识的属性
	private String ballName;

	public String getBallCode() {
		return ballCode;
	}

	public String getBallName() {
		return ballName;
	}

	public static BallEnum fromBallCode(String ballCode) {
		return codeToEnum.get(ballCode);
	}

	private static final Map<String, BallEnum> codeToEnum;
	static {
		codeToEnum = new LinkedHashMap<>();
		for (BallEnum e : values()) {
			codeToEnum.put(e.getBallCode(), e);
		}
	}

	BallEnum(String ballCode, String ballName) {
		this.ballCode = ballCode;
		this.ballName = ballName;
	}

	@JsonIgnore
	@Override
	public String getValue() {
		return getBallCode();
	}

	@JsonIgnore
	@Override
	public String getName() {
		return getBallName();
	}

}
